home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_grass_displace.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  1.3 KB  |  65 lines

  1. /* 
  2.  * grass.sl
  3.  *
  4.  * I took used some of RManNotes function to assist in
  5.  * creating a random look on the grass texture.
  6.  *
  7.  * This is simply uses the noise function and a checkerboard
  8.  * pattern.  The displacements are circular.
  9.  *
  10.  *   by Lawrence D. Chin, cs184-bo
  11.  */
  12.  
  13. #include "k3d_rmannotes.h"
  14.  
  15. displacement
  16. k3d_grass_displace ( float height = 1.0,
  17.               fac = 1.0,
  18.               size = 1.0,
  19.           size2 = 0.75; )
  20. {
  21.  
  22.   float noifreq = 5;
  23.   float noiscale = 0.4;
  24.   float ss, tt;
  25.  
  26.   float noi = noise(s * noifreq, t * noifreq);
  27.   ss = s + snoise(noi + 912) * noiscale;
  28.   tt = t + snoise(noi + 333) * noiscale;
  29.  
  30.   float smod = mod(ss*fac,1),
  31.         tmod = mod(tt*fac,1),
  32.         x,y,z;
  33.  
  34.   if (smod < 0.5) {
  35.     if (tmod < 0.5) 
  36.       P += 0.5;
  37.     else {
  38.       y = (tmod - 0.5)*10;
  39.       x = smod*10; 
  40.       x = abs(x - 2.5);
  41.       y = abs(y - 2.5);
  42.       z = sqrt(pow(x,2) + pow(y,2));
  43.       if (z <= size2 )
  44.     P += N * height;
  45.       else
  46.         P += 0.5;
  47.       }
  48.   } else {
  49.     if (tmod < 0.5) {
  50.       x = (smod - 0.5)*10;
  51.       y = tmod*10; 
  52.       x = abs(x - 2.5);
  53.       y = abs(y - 2.5);
  54.       z = sqrt(pow(x,2) + pow(y,2));
  55.       if (z <= size )
  56.     P += N * height;
  57.       else
  58.         P += 0.5;
  59.       } 
  60.     else
  61.       P += 0.5;
  62.  }    
  63.   N = calculatenormal(P);
  64. }
  65.